import http from "./http"
// 登录
const denglu = params => http.post('/login', params);
// 左侧菜单列表
const caidanlb = () => http.get("/menus");
// 获取用户列表
const yonghulb = params => http.get("/users", { params });
// 修改用户状态
const  yonghuzt= params => http.put(`/users/${params.uId}/state/${params.type}`);
// 添加用户
const tianjiayh = params => http.post("/users", params);
// 编辑用户信息
const yonghuxx = params => http.put(`/users/${params.id}`, params);
// 删除单个用户
const shanchuyh = params => http.delete(`/users/${params.id}`);
// 获取角色列表
const jiaoshelb = () => http.get("/roles");
// 分配用户角色
const fenpeijs = params => http.put(`/users/${params.uid}/role`,params);
// 添加角色
const postAddRole = params => http.post('/roles', params);
// 删除角色
const deleteRoles = params => http.delete(`/roles/${params.id}`);
// 所有权限列表
const quanxianlb = params => http.get(`/rights/${params.type}`);
// 编辑角色信息
const putRolesInfo = params => http.put(`/roles/${params.id}`, params);
// 删除角色指定权限
const scjszdqx = params => http.delete(`/roles/${params.roleId}/rights/${params.rightId}`);
// 给角色分配权限
const jsfpqx = params => http.post(`/roles/${params.roleId}/rights`,params);
// 获取商品列表
const getGoodList = params => http.get("/goods", { params });
// 通过商品id查询商品信息
const getGoodsInfo = params => http.get(`/goods/${params.id}`);
// 编辑商品信息
const putGoodsInfo = params => http.put(`/goods/${params.goods_id}`, params);
// 删除商品
const deleteGoods = params => http.delete(`/goods/${params.id}`);
// 添加商品
const postAddGoods = params => http.post("/goods", params);
// 获取订单列表
var getOrdersList = params => http.get('/orders', params)
// 根据ID查询商品
var getsearchGoods = params => http.get('/goods/' + params.id)
// 订单列表
var ordersList = params => http.get(`/orders?pagenum=${params.pagenum}&pagesize=${params.pagesize}`)
// 搜索订单
var Getorders = params => http.get(`/orders/${params.id}`, params)
// 修改订单状态
var puteditOrders = params => http.put(`/orders/${params.id}`, params)
// 获取商品分类数据
var getCategories = params => http.get('/categories', params)
// 添加分类
var postaddCategories = params => http.post('/categories', params)
// 删除分类
var deleteCategories = params => http.delete(`/categories/${params.id}`)
// 编辑提交参数
var puteditCategories = params => http.put(`/categories/${params.id}`, params)
// 分类参数列表
const getCateAttrs = params => http.get(`/categories/${params.id}/attributes`,{params});
// 添加动态参数或者静态属性
const postCateAttrs = params => http.post(`/categories/${params.id}/attributes`,params);
// 编辑动态参数或者静态属性
const putCateAttrs = params => http.put(`/categories/${params.id}/attributes/${params.attr_id}`,params);
// 删除动态参数或者静态属性
const deleteCateAttrs = params => http.delete(`/categories/${params.id}/attributes/${params.attr_id}`,params);
// 图片上传地址
const uploadUrl = http.defaults.baseURL + "/upload";
// 图片上传 
const postImg = formData => http({
    url: "/upload",
    method: "post",
    headers: { 
        // 文件上传的请求头需要设置数据类型multipart/form-data
        "Content-Type" : "multipart/form-data"
    },
    // 注意： 请求体中使文件数据， 不是对象， 不需要（qs）处理请求体
    transformRequest: data => data,
    data: formData  // 文件数据要放到formData对象中
})

// 数据统计
const getReports = ()=> http.get("/reports/type/1");
export { 
    denglu,
    caidanlb,
    yonghulb,
    yonghuzt,
    tianjiayh,
    yonghuxx,
    postaddCategories,
    deleteCategories,
    puteditCategories,
    shanchuyh,
    jiaoshelb,
    fenpeijs,
    quanxianlb,
    scjszdqx,
    jsfpqx,
    getGoodList,
    putRolesInfo,
    deleteRoles,
    getGoodsInfo,
    postAddRole,
    getOrdersList,
    ordersList,
    Getorders,
    getsearchGoods,
    puteditOrders,
    putGoodsInfo,
    deleteGoods,
    postAddGoods,
    getCategories,
    getCateAttrs,
    postCateAttrs,
    putCateAttrs,
    deleteCateAttrs,
    uploadUrl,
    postImg,
    getReports
}
